<template>
    <div id="Detail">
        <div class="detail">
            <v-navMenu
                :detailNav="detailNav"
                @setMentActive="setMentActive"
            ></v-navMenu>
            <component :inputData="detailData" :is="currentComponent"></component>
        </div>
    </div>
</template>

<script>
import navMenu from "commons/NavMenu";
import baseMixin from "@/mixins/BaseMixin";

export default {
    name: "Detail",
    mixins: [baseMixin],
    data() {
        return {
            flag: true,
            newFlag: false,
            selectData: {},
            detailData: {
                serialkey: null,
                whseid: null,
                receiptpreflightkey: this.$store.state.routeId,
                receipttype: "1",
                storerkey: null,
                sku: null,
                generatedate: null,
                lastdate: null,
                vendor: null,
                vendortype: null,
                vendorbatch: null,
                vendorfifospec: null,
                fifooutqty: null,
                lcallowlimitspec: null,
                lcallowoutqty: null,
                skuneed: null,
                samplebatch: null,
                conformfifo: null,
                exceedlcallowtime: null,
                receipt: null,
                adddate: null,
                addwho: null,
                editdate: null,
                editwho: null,
                importkey: null,
                excelgroupkey: null,
                receiptkey: null,
                legalkey: null,
                potype: 'OP',
                pono: null,
                uom: 'EA',
                quarantine: null,
                liquorticket: null,
                origin: null,
                vendorrejcet: null,
                specialresult: null,
                flag: null,
                vendorrejcetoutqty: null,
                arrivalqty: null,
                expectedreceiptdate: null,
                extsku: null,
                extsupplykey: null,
                externpokey: null,
                eorderkey: null,
                eorderlinenum: null,
                token: null,
                jdewarehouse: null,
                entSerialkey: null,
                lottable08: null,
                disitekey: null,
                consigneekey: null,
                expectedrestaurantdate: null,
                expecteddate: null,
                vmiorderkey: null
            },
            detailNav: "1",
            componentConfig: [
                {
                    name: "ReceiptPreflightDetails",
                    label: this.$t('common.detail'),
                    component: () => import('./page/ReceiptPreflightDetails.vue')
                }
            ]
        }
    },
    computed: {
        currentComponent() {
            return this.componentConfig[this.detailNav - 1].component;
        }
    },
    methods: {
        setMentActive(key) {
            this.detailNav = key;
        },
        async getData() {
            try {
                let res = await this.$api.post(`/receiptPreflight/${this.selectData.receiptpreflightkey}`,{});
                
                    this.detailData = res.data.data;
                
            } catch (e) {
                this.$message.error(e);
            }
        },
    },
    mounted() {
        this.newFlag = this.$store.state.newFlag;
        if (Object.keys(this.$store.state.skip).length !== 0) {
            let data = this.$store.state.skip;
            this.detailData = data.detail;
            this.selectData = data.routeData;
            this.detailNav = data.detailNav;
        } else if (!this.newFlag) {
            this.selectData = this.$store.state.routeData;
            this.getData();
        }
    },
    watch: {},
    components: {
        "v-navMenu": navMenu
    },
}
</script>

<style scoped>

</style>
